﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace ChicagoDealsN
{
    public class BizPurchaseHistory
    {
        private static DataPurchaseHistory dph;
        private DataPurchaseHistory getObject()
        {
            if (dph != null)
                return dph;
            else
                dph=new DataPurchaseHistory();
            return dph;
        }

        public bool purchaseDeal(int User_Id, int Deal_Id, int balToSetAfterPur)
        {
            DateTime dt = DateTime.Now;
            DataPurchaseHistory dpl = getObject();
            dpl.newPurchaseHistory(User_Id, Deal_Id,dt);

            return dpl.updateBalance(User_Id, balToSetAfterPur);
        }

        public DataTable getPurchaseHistory(int User_Id)
        {
            DataPurchaseHistory dpl = getObject();
            return dpl.getPurchaseHistoryFromUserId(User_Id).Tables["AllPUrchaseDoneByUser"];
        }

        // THIS WILL BE EXPOSED BY WEB SERVICE
        public bool BLRedeemCode(string code)
        {
            DataPurchaseHistory dpl = getObject();
            DateTime red_date = DateTime.Now;
            return dpl.DLRedeemCode(code,red_date);
        }
    }
}